<?php
namespace app\controller\api;
use app\controller\Common;
use think\Db;
use think\Model;

class Sms extends Common{

  public function send(){
    $mobile = request()->post('mobile');
    if(!$mobile){
      $result['ret'] = 0;
      $result['msg'] = '手机号不能为空';
      return json($result);
    }
    if(strlen($mobile)!=11 || !is_numeric($mobile)){
      $result['ret'] = 0;
      $result['msg'] = '手机号格式有误';
      return json($result);
    }
    $result = model('Sms')->send($mobile);
    return json($result);
  }

  public function check(){
    $mobile = request()->post('mobile');
    $code = request()->post('code');
    if(!$mobile){
      $result['ret'] = 0;
      $result['msg'] = '手机号不能为空';
      return json($result);
    }
    if(strlen($mobile)!=11 || !is_numeric($mobile)){
      $result['ret'] = 0;
      $result['msg'] = '手机号格式有误';
      return json($result);
    }
    if(!$code){
      $result['ret'] = 0;
      $result['msg'] = '验证码不能为空';
      return json($result);
    }
    if(strlen($code)!=6 || !is_numeric($code)){
      $result['ret'] = 0;
      $result['msg'] = '验证码不正确';
      return json($result);
    }
    $result = model('Sms')->check($mobile,$code);
    return json($result);
  }



}//END